package com.xxxx.crm.service;

import com.xxxx.crm.base.BaseService;

import com.xxxx.crm.dao.CustomerMapper;
import com.xxxx.crm.vo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerService extends BaseService<Customer, Integer> {

    @Resource
    private CustomerMapper customerMapper;

    /**
     * 生成折线图
     * @return
     */
    public Map<String,Object> countCustomerMake(){
        Map<String,Object> map=new HashMap<>();
        //查询客户列表
        List<Map<String,Object>> datalist=customerMapper.countCustomerMake();
        //折线图X轴的数据-数组
        List<String> data1=new ArrayList<>();
        //折线图Y轴的数据-数组
        List<String> data2=new ArrayList<>();
        //判断数组列表，循环输出数据
        if(datalist.size()>0 && datalist!=null){
            datalist.forEach(m->{
                //设置x轴坐标的数据
                data1.add(m.get("level").toString());
                //设置y轴地数据
                data2.add(m.get("total").toString());
            });
        }
        //将data1和data2设置到map中返回给前端
        map.put("data1",data1);
        map.put("data2",data2);
        return map;

    }


    /**
     * 生成饼状图
     * @return
     */
    public Map<String,Object> countCustomerMake02(){
        Map<String,Object> map=new HashMap<>();
        //查询客户列表
        List<Map<String,Object>> datalist=customerMapper.countCustomerMake();
        //饼状图X轴的数据-数组(数组中是字符串)
        List<String> data1=new ArrayList<>();
        //饼状图Y轴的数据-数组(数组中是对象)
        List<Map<String,Object>> data2=new ArrayList<>();
        //判断数组列表，循环输出数据
        if(datalist.size()>0 && datalist!=null){
            datalist.forEach(m->{
                //设置x轴
                data1.add(m.get("level").toString());
                //设置y轴
                Map<String,Object> datamap=new HashMap<>();
                datamap.put("name",m.get("level"));
                datamap.put("value",m.get("total"));
                data2.add(datamap);
            });
        }
        //将data1和data2设置到map中返回给前端
        map.put("data1",data1);
        map.put("data2",data2);
        return map;

    }



}
